﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.Mobile.ObjectBuilder;

namespace ColdBootObjectBuilder
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			var builder = new Builder();
			var mappings = new TypeMappingPolicy(typeof(IWebApp), null);

			builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(WebApp), null), typeof(IWebApp), null);
			builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Authenticator), null), typeof(IAuthenticator), null);
			builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(StockQuote), null), typeof(IStockQuote), null);
			builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Database), null), typeof(IDatabase), null);
			builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(ErrorHandler), null), typeof(IErrorHandler), null);
			builder.Policies.Set<ITypeMappingPolicy>(new TypeMappingPolicy(typeof(Logger), null), typeof(ILogger), null);

			Action action = () =>
			{
				var webApp = builder.BuildUp<IWebApp>(new NullLocator(), null, null);
				webApp.Run();
			};

			action();

			Close();
		}
	}
}